"""
题目：删除双链表中所有节点，返回 None。
"""


class Node:
    def __init__(self, val=0, prev=None, next=None):
        self.val = val
        self.prev = prev
        self.next = next


def clear(head):
    """清空双链表（断开所有节点连接）"""
    current = head
    while current:
        next_node = current.next  # 保存下一个节点
        # 断开当前节点的前驱和后继（可选，帮助垃圾回收）
        current.prev = None
        current.next = None
        current = next_node
    return None  # 清空后返回None


def create_doubly_linked_list(arr):
    if not arr:
        return None
    head = Node(arr[0])
    current = head
    for val in arr[1:]:
        new_node = Node(val)
        current.next = new_node
        new_node.prev = current
        current = new_node
    return head


def traverse(head):
    result = []
    current = head
    while current:
        result.append(current.val)
        current = current.next
    return result


# 测试
if __name__ == "__main__":
    head = create_doubly_linked_list([1, 2, 3])
    empty_head = clear(head)
    print(traverse(empty_head))  # 输出: []

    empty_list = create_doubly_linked_list([])
    print(traverse(clear(empty_list)))  # 输出: []